﻿//显示评论回复的内容表格
function ShowReplyDiv(commentId) {
    $("#ReplyCommentList_" + commentId).toggle();
    if ($("#ReplyCommentList_" + commentId).attr("style") == "display: none; ") {
        return;
    }
    //加载数据评论列表
    var requestUrl = "/WebHandler/CommentReply.ashx?action=get&commentId=" + commentId;
    $.ajax({
        url: requestUrl,
        dataType: 'json',
        success: function (data) {
            if (data != null) {
                var tableHtml = "";
                for (var i = 0; i < data.length; i++) {
                    tableHtml += "<p>";
                    tableHtml += data[i].ReplyContent;
                    tableHtml += "</p>";

                    tableHtml += "<p>";
                    tableHtml += Datefomatter(data[i].CreateDT);
                    tableHtml += " 来自于" + data[i].UserName;
                    tableHtml += "</p>";
                }
                $("#DivReplyCommentContent_" + commentId).html(tableHtml);
                $("#DivReplyCommentContent_" + commentId).show();
            }
        }
    });
}

function ReplyCommentSend(commentId) {
    var replyContent = $("#replyCommentContent_" + commentId)[0].value;
    var requestUrl = "/WebHandler/CommentReply.ashx?action=add&commentId=" + commentId + "&replyContent=" + replyContent;
    $.ajax({
        url: requestUrl,
        dataType: 'json',
        success: function (data) {
            if (data != null) {
                var tableHtml = "";
                for (var i = 0; i < data.length; i++) {
                    tableHtml += "<p>";
                    tableHtml += data[i].ReplyContent;
                    tableHtml += "</p>";

                    tableHtml += "<p>";
                    tableHtml += Datefomatter(data[i].CreateDT);
                    tableHtml += " 来自于" + data[i].UserName;
                    tableHtml += "</p>";
                }
                $("#DivReplyCommentContent_" + commentId).html(tableHtml);
                $("#DivReplyCommentContent_" + commentId).show();
            }
        }
    });
}

function ShowBiggerPic(object) {
    $(object).attr("width", "200");
    $(object).attr("height", "150");
}

function Datefomatter(value) {
    if (value == null)
        return;
    var date = eval('new ' + (value.replace(/\//g, '')));
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    var d = date.getDate();
    var h = date.getHours();
    var mis = date.getMinutes();
    var s = date.getSeconds();
    var now = y + "-" + (m < 10 ? '0' + m : m) + "-" + (d < 10 ? '0' + d : d) + " " + (h < 10 ? '0' + h : h)
        + ":" + (mis < 10 ? '0' + mis : mis) + ":" + (s < 10 ? '0' + s : s);
    return now;
}

//图片按比例缩放
function DrawImage(Img, WIDTH, HEIGHT) {
    var image = new Image();
    image.src = Img.src;
    width = WIDTH; //预先设置的所期望的宽的值
    height = HEIGHT; //预先设置的所期望的高的值
    if (image.width > width || image.height > height) {//现有图片只有宽或高超了预设值就进行js控制
        w = image.width / width;
        h = image.height / height;
        if (w > h) {//比值比较大==>宽比高大
            //定下宽度为width的宽度
            Img.width = width;
            //以下为计算高度
            Img.height = image.height / w;

        } else {//高比宽大
            //定下宽度为height高度
            img.height = height;
            //以下为计算高度
            Img.width = image.width / h;
        }
    }
}